//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved

#pragma once

// Material:
// This class maintains the properties that represent how an object will
// look when it is rendered.  This includes the color of the object, the
// texture used to render the object, and the vertex and pixel shader that
// should be used for rendering.
// The RenderSetup method sets the appropriate values into the constantBuffer
// and calls the appropriate D3D11 context methods to set up the rendering pipeline
// in the graphics hardware.

#include "Rendering/ConstantBuffers.h"

ref class Material
{
internal:
	Material(
		DirectX::XMFLOAT4 meshColor,
		DirectX::XMFLOAT4 diffuseColor,
		DirectX::XMFLOAT4 specularColor,
		float specularExponent,
		float meshColorBlendPercent,
		float specularColorBlendPercent,
		_In_ ID3D11ShaderResourceView* textureResourceView,
		_In_ ID3D11VertexShader* vertexShader,
		_In_ ID3D11PixelShader* pixelShader
		);

	virtual void RenderSetup(
		_In_ ID3D11DeviceContext* context,
		_In_ DirectX::XMFLOAT4X4& world,
		_In_ ID3D11Buffer* primitiveConstantBuffer,
		_In_ bool isFirstPass
		);

	__forceinline void SetTexture(_In_ ID3D11ShaderResourceView* textureResourceView) { m_textureRV = textureResourceView; }

	__forceinline void DiffuseTint(DirectX::XMFLOAT4 color) { m_diffuseColor = color; }
	__forceinline DirectX::XMFLOAT4 DiffuseTint() { return m_diffuseColor; }

	__forceinline void MeshColor(DirectX::XMFLOAT4 color) { m_meshColor = color; }
	__forceinline DirectX::XMFLOAT4 MeshColor() { return m_meshColor; }

	__forceinline void MeshPercent(float meshPercent) { m_meshPercentDiffusePercent.x = meshPercent; }
	__forceinline void DiffusePercent(float diffusePercent) { m_meshPercentDiffusePercent.y = diffusePercent; }
	__forceinline DirectX::XMFLOAT4 MeshPercentDiffusePercent() { return m_meshPercentDiffusePercent; }
	
	__forceinline void OriginalColor(DirectX::XMFLOAT4 color) { m_originalColor = color; }
	__forceinline DirectX::XMFLOAT4 OriginalColor() { return m_originalColor; }

	__forceinline void SpecularExponent(float specularExponent) { m_specularExponent = specularExponent; }
	__forceinline float SpecularExponent() { return m_specularExponent; }

protected private:
	DirectX::XMFLOAT4	m_originalColor;
	DirectX::XMFLOAT4   m_meshColor;
	DirectX::XMFLOAT4   m_diffuseColor;
	DirectX::XMFLOAT4   m_hitColor;
	DirectX::XMFLOAT4   m_specularColor;
	DirectX::XMFLOAT4	m_meshPercentDiffusePercent;
	float               m_specularExponent;

	Microsoft::WRL::ComPtr<ID3D11VertexShader>       m_vertexShader;
	Microsoft::WRL::ComPtr<ID3D11PixelShader>        m_pixelShader;
	Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_textureRV;
};
